---
title: ChatQwQ
---

This will help you get started with QwQ [chat models](../../concepts/chat_models). For detailed documentation of all ChatQwQ features and configurations head to the [API reference](https://pypi.org/project/langchain-qwq/).

## Overview

### Integration details

| Class | Package | Local | Serializable | Downloads | Version |
| :--- | :--- | :---: |  :---: | :---: | :---: |
| [ChatQwQ](https://pypi.org/project/langchain-qwq/) | [langchain-qwq](https://pypi.org/project/langchain-qwq/) | ❌ | beta | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain-qwq?style=flat-square&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-qwq?style=flat-square&label=%20) |

### Model features

| [Tool calling](../../how_to/tool_calling.ipynb) | [Structured output](../../how_to/structured_output.ipynb) | JSON mode | [Image input](../../how_to/multimodal_inputs.ipynb) | Audio input | Video input | [Token-level streaming](../../how_to/chat_streaming.ipynb) | Native async | [Token usage](../../how_to/chat_token_usage_tracking.ipynb) | [Logprobs](../../how_to/logprobs.ipynb) |
| :---: | :---: | :---: | :---: |  :---: | :---: | :---: | :---: | :---: | :---: |
| ✅ | ✅ | ✅ |✅  | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ |

## Setup

To access QwQ models you'll need to create an Alibaba Cloud account, get an API key, and install the `langchain-qwq` integration package.

### Credentials

Head to [Alibaba's API Key page](https://account.alibabacloud.com/login/login.htm?oauth_callback=https%3A%2F%2Fbailian.console.alibabacloud.com%2F%3FapiKey%3D1&lang=en#/api-key) to sign up to Alibaba Cloud and generate an API key. Once you've done this set the `DASHSCOPE_API_KEY` environment variable:

```python
import getpass
import os

if not os.getenv("DASHSCOPE_API_KEY"):
    os.environ["DASHSCOPE_API_KEY"] = getpass.getpass("Enter your Dashscope API key: ")
```

### Installation

The LangChain QwQ integration lives in the `langchain-qwq` package:

```python
%pip install -qU langchain-qwq
```

## Instantiation

Now we can instantiate our model object and generate chat completions:

```python
from langchain_qwq import ChatQwQ

llm = ChatQwQ(
    model="qwq-plus",
    max_tokens=3_000,
    timeout=None,
    max_retries=2,
    # other params...
)
```

## Invocation

```python
messages = [
    (
        "system",
        "You are a helpful assistant that translates English to French."
        "Translate the user sentence.",
    ),
    ("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg
```

```output
AIMessage(content="J'aime la programmation.", additional_kwargs={'reasoning_content': 'Okay, the user wants me to translate "I love programming." into French. Let\'s start by breaking down the sentence. The subject is "I", which in French is "Je". The verb is "love", which in this context is present tense, so "aime". The object is "programming". Now, "programming" in French can be "la programmation". \n\nWait, should it be "programmation" or "programmation"? Let me confirm the spelling. Yes, "programmation" is correct. Now, putting it all together: "Je aime la programmation." Hmm, but in French, there\'s a tendency to contract "je" and "aime". Wait, actually, "je" followed by a vowel sound usually takes "j\'". So it should be "J\'aime la programmation." \n\nLet me double-check. "J\'aime" is the correct contraction for "I love". The definite article "la" is needed because "programmation" is a feminine noun. Yes, "programmation" is a feminine noun, so "la" is correct. \n\nIs there any other way to say it? Maybe "J\'adore la programmation" for "I love" in a stronger sense, but the user didn\'t specify the intensity. Since the original is straightforward, "J\'aime la programmation." is the direct translation. \n\nI think that\'s it. No mistakes there. So the final translation should be "J\'aime la programmation."'}, response_metadata={'model_name': 'qwq-plus'}, id='run-5045cd6a-edbd-4b2f-bf24-b7bdf3777fb9-0', usage_metadata={'input_tokens': 32, 'output_tokens': 326, 'total_tokens': 358, 'input_token_details': {}, 'output_token_details': {}})
```

## Chaining

We can [chain](../../how_to/sequence.ipynb) our model with a prompt template like so:

```python
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate(
    [
        (
            "system",
            "You are a helpful assistant that translates"
            "{input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

chain = prompt | llm
chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)
```

```output
AIMessage(content='Ich liebe das Programmieren.', additional_kwargs={'reasoning_content': 'Okay, the user wants me to translate "I love programming." into German. Let me think. The verb "love" is "lieben" or "mögen" in German, but "lieben" is more like love, while "mögen" is prefer. Since it\'s about programming, which is a strong affection, "lieben" is better. The subject is "I", which is "ich". Then "programming" is "Programmierung" or "Coding". But "Programmierung" is more formal. Alternatively, sometimes people say "ich liebe es zu programmieren" which is "I love to program". Hmm, maybe the direct translation would be "Ich liebe die Programmierung." But maybe the more natural way is "Ich liebe es zu programmieren." Let me check. Both are correct, but the second one might sound more natural in everyday speech. The user might prefer the concise version. Alternatively, maybe "Ich liebe die Programmierung." is better. Wait, the original is "programming" as a noun. So using the noun form would be appropriate. So "Ich liebe die Programmierung." But sometimes people also use "Coding" in German, like "Ich liebe das Coding." But that\'s more anglicism. Probably better to stick with "Programmierung". Alternatively, "Programmieren" as a noun. Oh right! "Programmieren" can be a noun when used in the accusative case. So "Ich liebe das Programmieren." That\'s correct and natural. Yes, that\'s the best translation. So the answer is "Ich liebe das Programmieren."'}, response_metadata={'model_name': 'qwq-plus'}, id='run-2c418451-51d8-4319-8269-2ce129363a1a-0', usage_metadata={'input_tokens': 28, 'output_tokens': 341, 'total_tokens': 369, 'input_token_details': {}, 'output_token_details': {}})
```

## Tool Calling

ChatQwQ supports tool calling API that lets you describe tools and their arguments, and have the model return a JSON object with a tool to invoke and the inputs to that tool.

### Use with `bind_tools`

```python
from langchain_core.tools import tool
from langchain_qwq import ChatQwQ


@tool
def multiply(first_int: int, second_int: int) -> int:
    """Multiply two integers together."""
    return first_int * second_int


llm = ChatQwQ()

llm_with_tools = llm.bind_tools([multiply])

msg = llm_with_tools.invoke("What's 5 times forty two")

print(msg)
```

```output
content='' additional_kwargs={'reasoning_content': 'Okay, the user is asking "What\'s 5 times forty two". Let me break this down. First, I need to identify the numbers involved. The first number is 5, which is straightforward. The second number is forty two, which is 42 in digits. The operation they want is multiplication.\n\nLooking at the tools provided, there\'s a function called multiply that takes two integers. So I should use that. The parameters are first_int and second_int. \n\nI need to convert "forty two" to 42. Since the function requires integers, both numbers should be in integer form. So 5 and 42. \n\nNow, I\'ll structure the tool call. The function name is multiply, and the arguments should be first_int: 5 and second_int: 42. I\'ll make sure the JSON is correctly formatted without any syntax errors. Let me double-check the parameters to ensure they\'re required and of the right type. Yep, both are required and integers. \n\nNo examples were provided, but the function\'s purpose is clear. So the correct tool call should be to multiply those two numbers. I think that\'s all. No other functions are needed here.'} response_metadata={'model_name': 'qwq-plus'} id='run-638895aa-fdde-4567-bcfa-7d8e5d4f24af-0' tool_calls=[{'name': 'multiply', 'args': {'first_int': 5, 'second_int': 42}, 'id': 'call_d088275851c140529ed2ad', 'type': 'tool_call'}] usage_metadata={'input_tokens': 176, 'output_tokens': 277, 'total_tokens': 453, 'input_token_details': {}, 'output_token_details': {}}
```

### Vision Support
#### Image
```python
from langchain_core.messages import HumanMessage

model = ChatQwQ(model="qvq-max-latest")

messages = [
    HumanMessage(
        content=[
            {
                "type": "image_url",
                "image_url": {"url": "https://example.com/image/image.png"},
            },
            {"type": "text", "text": "What do you see in this image?"},
        ]
    )
]

response = model.invoke(messages)
print(response)
```
```output
content='The image captures a heartwarming moment on a sandy beach at sunset. A young woman with long dark hair sits cross-legged on the sand, wearing a plaid shirt and jeans, her face lit up with a joyful smile as she engages with her golden Labrador Retriever. The dog, adorned with a blue harness featuring colorful patterns, sits upright on its hind legs, playfully extending its front paws toward the woman as if offering a "high-five." Their interaction exudes warmth and companionship, suggesting a deep bond between them.\n\nThe backdrop features a tranquil ocean with gentle waves rolling onto the shore, while the sky transitions from a soft light blue to warm golden hues near the horizon, enhancing the serene and nostalgic atmosphere. Footprints scatter across the sand, adding texture to the scene. The woman’s red leash lies loosely beside her, and both she and the dog appear relaxed and content in each other’s company. The overall mood is one of joy, peace, and cherished connection, perfectly framed by the golden hour light.' additional_kwargs={'reasoning_content': 'Okay, let\'s see. The user is asking what I see in this image. Alright, first I need to describe the scene accurately. Let me start by looking at the main elements.\n\nThere\'s a woman and a dog on a beach. The setting seems to be during sunset because the sky has that warm, golden hue. The woman is sitting on the sand, wearing a plaid shirt and jeans. She\'s smiling and interacting with the dog. The dog looks like a Labrador Retriever, maybe yellow or golden in color. It\'s sitting upright on its hind legs, reaching out with its front paws towards the woman. They seem to be playing a game, maybe "high-five" or something similar.\n\nThe background shows the ocean with some waves coming in. The sand has footprints, which adds to the beach atmosphere. The lighting is soft and warm, creating a cozy, peaceful mood. Both the woman and the dog look happy and relaxed. The overall vibe is cheerful and friendly, capturing a moment of bonding between them.\n\nWait, should I mention the colors more specifically? The woman\'s shirt is plaid, probably blue and white or another color combination. The dog\'s harness is blue with colorful patterns. The sky gradients from light blue to orange near the horizon. The sand is a typical beach sand color, maybe light brown or tan.\n\nIs there anything else notable? The dog\'s tail is visible, curled around. The woman\'s hair is long and dark, flowing behind her. The interaction between them is the focal point, showing their connection. The image composition balances the subjects with the expansive beach and ocean in the background.\n\nI should make sure to highlight the emotional aspect – the joy and companionship. Maybe mention how the sunset enhances the romantic or serene feel of the scene. Also, note that it\'s a candid moment, not posed, which makes it feel more genuine.\n\nLet me check if I missed any details. The dog\'s leash is red, lying on the sand next to them. That\'s an important detail. The woman is barefoot, which is typical for a beach setting. The waves are gentle, not too rough, contributing to the calm atmosphere.\n\nAlright, putting it all together: describe the setting, the subjects, their actions, the environment, colors, lighting, and the overall mood. Make sure to convey the warmth and happiness in the scene.\n'} response_metadata={'model_name': 'qvq-max-latest'} id='run--94ecc956-1fee-4572-b3e9-27507e8e48df-0' usage_metadata={'input_tokens': 1265, 'output_tokens': 696, 'total_tokens': 1961, 'input_token_details': {}, 'output_token_details': {}}
```

#### Video
```python
from langchain_core.messages import HumanMessage

model = ChatQwQ(model="qvq-max-latest")

messages = [
    HumanMessage(
        content=[
            {
                "type": "video_url",
                "video_url": {"url": "https://example.com/video/1.mp4"},
            },
            {"type": "text", "text": "Can you tell me about this video?"},
        ]
    )
]

response = model.invoke(messages)
print(response)
```

```output
content='The image provided is a still frame featuring a young Asian woman with short, layered brown hair and bangs, showcasing a bright, friendly smile. She appears to be in her late teens or early twenties. Here\'s a detailed breakdown:\n\n### **Appearance & Attire**\n- **Hair**: Short, chestnut-brown hairstyle with a neat fringe, styled in a modern, youthful manner.\n- **Clothing**: A casual ensemble consisting of a white round-neck t-shirt layered under a soft pink knitted cardigan. The outfit suggests a relaxed, approachable vibe.\n- **Accessories**: A delicate silver necklace with a small pendant, adding a subtle touch of elegance.\n\n### **Setting & Lighting**\n- **Background**: Blurred architectural elements (likely buildings) hint at an outdoor urban setting, possibly a campus or city street.\n- **Lighting**: Natural, warm daylight illuminates her face, enhancing her cheerful expression and creating a welcoming atmosphere.\n\n### **Key Details**\n- **Expression**: Her broad smile and lively eyes convey happiness and confidence, making the image feel energetic and positive.\n- **Watermark**: The text "通义·AI合成" ("Tongyi AI Synthesis") in the top right corner indicates this image was generated by Alibaba\'s Tongyi AI model, known for creating hyper-realistic human portraits.\n\n### **Possible Video Context**\nWhile the image is a still, if part of a video, it likely showcases the AI\'s capability to generate dynamic, lifelike human visuals. The video may demonstrate:\n- Real-time facial expressions or animations.\n- Seamless integration of AI-generated characters into realistic environments.\n- Applications in virtual influencers, gaming, or interactive media.\n\n### **Conclusion**\nThis image highlights the advanced realism achievable with modern AI synthesis, blending natural human features with a vibrant, relatable aesthetic. If the video expands on this, it would emphasize the technology\'s potential in creative industries. Let me know if you\'d like further analysis! 😊' additional_kwargs={'reasoning_content': 'Okay, let\'s see. The user is asking about this video, but the image provided is a still frame of a young woman. First, I need to figure out what information they\'re looking for. Since it\'s a single image, maybe they want a description of the scene or details about the person in the picture.\n\nThe image shows a young Asian woman with short brown hair and bangs. She\'s smiling brightly, which gives off a cheerful vibe. Her outfit is casual: a white t-shirt under a pink knitted cardigan. There\'s a necklace visible, adding a subtle accessory. The background is blurred, but it looks like an outdoor setting with buildings, suggesting an urban environment. The lighting is natural and warm, indicating it might be daytime.\n\nI should mention her appearance, clothing, expression, and the setting. Also, there\'s a watermark in the top right corner that says "通义·AI合成", which translates to "Tongyi AI Synthesis". That\'s important because it indicates the image was generated by AI, specifically Alibaba\'s Tongyi model. The user might not realize it\'s AI-generated, so pointing that out is crucial.\n\nWait, the user asked about the video, but the image is a still. Maybe the video is related to this AI-generated image? Perhaps it\'s a promotional video for the AI model, showcasing its ability to create realistic human images. The watermark reinforces that connection. I should explain that while the image is a still, it\'s part of an AI-generated content, possibly from a video demonstrating the technology.\n\nI need to make sure to cover all aspects: description of the subject, her attire, the setting, the AI aspect, and the possible context of the video. Also, note the quality and realism of the image to highlight the AI\'s capabilities. The user might be interested in how realistic the AI generation is, so emphasizing the details like her smile, hair texture, and natural lighting would be good.\n\nCheck if there\'s any other information needed. The user didn\'t specify, so providing a comprehensive description covering visual elements and the AI aspect should suffice. Make sure to structure the answer clearly, starting with the subject, then clothing, setting, AI details, and possible video context.\n'} response_metadata={'model_name': 'qvq-max-latest'} id='run--fd74c9a3-8c40-4a5a-ac31-30b9c484f762-0' usage_metadata={'input_tokens': 4554, 'output_tokens': 857, 'total_tokens': 5411, 'input_token_details': {}, 'output_token_details': {}}
```
## API reference

For detailed documentation of all ChatQwQ features and configurations head to the [API reference](https://pypi.org/project/langchain-qwq/)
